function _carrousel(){
	var that = this
	var imgArray = []
	var defaults = {
		cntr: '#carrousle' //容器id
		, startIndex: 2 //首次焦点图片的索引
		, focuScale: 1.5 //焦点图片的倍数
		, nonFocuScale: 0.8 //非焦点图片的倍数
		, border: -20 //图片之间的间距
        , nextBtn: '.nextBtn'
        , prevBtn: '.prevBtn'
	}
	function creatObj(obj){
		this.ow = obj.width()
		this.oh = obj.height()
		this.r = this.ow / this.oh
		this.cw = this.ow
		this.ch = this.oh
		this.x = 0
		this.y = 0
        this.z = 0
        this.o = 1
		this.$el = obj
	}
	that.init = function(opts){
		for (var name in defaults) {
            that[name] = (opts !== undefined && opts[name] !== undefined) ? opts[name] : defaults[name]
        }
		var $cntr = that.$cntr = $(that.cntr)
		that.$imgs = $cntr.find('.images')
		var $imgItem = $cntr.find('.imgItem')
		that.cntrW = $cntr.width()
		that.cntrH = $cntr.height()
		that.imgItemW = $imgItem.width()
		that.imgItemH = $imgItem.height()
		that.imgNum = $imgItem.length
        that.$prevBtn = $cntr.find(that.prevBtn)
        that.$nextBtn = $cntr.find(that.nextBtn)
        that.current = that.startIndex
		that.$imgs.width(that.imgNum * (that.imgItemW + that.border))
		for(var i = 0;i < that.imgNum;i++){
			imgArray.push( new creatObj($imgItem.eq(i)))
		}
        that.event()
		that.calc(that.startIndex)
	}

	that.calc = function(index){
		var me = imgArray[index]
		var x = 0
        var z = that.imgNum
        var imgsH = that.$imgs.height()
        var cover = that.$cntr.find('.cover')
        var imgTitleH = that.$imgs.find('.imgTitle').height()
        cover.css({'z-index':z})
		me.ch = me.oh * that.focuScale
		me.cw =  me.ch * me.r
        me.x = that.cntrW / 2 - me.cw / 2
		me.y = imgsH / 2 - me.ch /2
        me.z = z + 1;
        me.o = 1
		x = me.x + me.cw + that.border
        console.log(me.x ,x)
		// 计算右边图片位置
		for(var i = index + 1; i < that.imgNum; i++){
			var cur = imgArray[i]
            cur.z = --z
            cur.o = 1
			cur.x = x
			cur.ch = cur.oh * that.nonFocuScale
			cur.cw =  cur.ch * cur.r
			cur.y = imgsH / 2 - cur.ch / 2
			x = cur.x + cur.cw + that.border
		}
        // 计算左边图片位置
        x = me.x
        z = imgArray.length
        for(var i = index - 1; i >= 0; i--){
            var cur = imgArray[i]
            cur.z = --z
            cur.o = 1
            cur.ch = cur.oh * that.nonFocuScale
            cur.cw =  cur.ch * cur.r
            cur.y = imgsH / 2 - cur.ch /2
            x -= cur.cw + that.border
            cur.x = x
        }
        that.fresh()
	}
    that.fresh = function(){
        for(var i in imgArray){
            imgArray[i].$el.stop()
            imgArray[i].$el.animate({
                top: imgArray[i].y
                , 'left':imgArray[i].x
                , 'width':imgArray[i].cw
                , 'height':imgArray[i].ch
                , 'z-index':imgArray[i].z
                , 'opacity':imgArray[i].o
            },500)
        }
        that.$cntr.trigger('carrousel',that)
    }
    that.event = function(){
        that.$nextBtn.on('click',function(){
            that.current++
            if(that.current > that.imgNum - 1){
                that.current = that.imgNum - 1
                return
            }
            that.calc(that.current)
        })
        that.$prevBtn.on('click',function(){
            that.current--
            if(that.current < 0){
                that.current = 0
                return
            }
            that.calc(that.current)
        })

    }
}
	var carrousel = new _carrousel()
	carrousel.init()
    $('body').on('carrousel',function(e,m){
        console.log(m)
    })